package com.xiaoluyy.demo.biz.impl;

import com.xiaoluyy.demo.biz.IAddressBizService;
import com.xiaoluyy.demo.common.domain.po.Address;
import com.xiaoluyy.demo.core.dao.AddressMapper;
import com.xiaoluyy.common.log.LogFactory;
import com.xiaoluyy.common.log.ILog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Service
public class AddressBizServiceImpl implements IAddressBizService {

    private static  final ILog LOG = LogFactory.getLog(AddressBizServiceImpl.class);

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public Integer addAddress(Address address) {
        address.setIsValid(true);
        int i = this.addressMapper.insertSelective(address);
        if (i<1)
        {
            return  null;
        }else {
            return  address.getId();
        }
    }

    @Override
    public Integer modifyAddress(int addressId, Address address) {
        address.setId(addressId);

        int i = 0;
        i = addressMapper.updateByIdSelective(address);
        if (i<1)
        {
            return  null;
        }else {
            return i;
        }
    }

    @Override
    public Address queryAddress(int addressId) {
        return addressMapper.selectById(addressId);
    }

    @Override
    public Integer deleteAddress(int addressId) {
        Map<String,Object> conds = new HashMap<>();
        conds.put("id",addressId);
        int i = 0;
        i = addressMapper.deleteByIdDynamically(conds);
        if (i<1)
        {
            return  null;
        }else {
            return i;
        }
    }
}
